package com.friends.common.tools.util;

/**
 * Created by fusio on 2018/9/15.
 */
public class HttpMessage {

    /*    Map<String,Object> resultMap = new HashMap<String,Object>(3);
        resultMap.put("code", ResultCode.SUCCESS.getCode());
        resultMap.put("msg",ResultCode.SUCCESS.getMsg());
        resultMap.put("result",accountOrgPage);
        resultMap.put("accessToken",request.getAttribute("accessToken"));*/
    String code;
    String msg;
    Object result;
    Object accessToken;
    String sessionId;

    public void setSessionId(String sessionId) {
        this.sessionId = sessionId;
    }

    public void setAccessToken(Object accessToken) {
        this.accessToken = accessToken;
    }

    public String getSessionId() {
        return sessionId;
    }

    public String getCode() {
        return code;
    }

    public void setCode(String code) {
        this.code = code;
    }

    public String getMsg() {
        return msg;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }

    public Object getResult() {
        return result;
    }

    public void setResult(Object result) {
        this.result = result;
    }

    public Object getAccessToken() {
        return accessToken;
    }

    public HttpMessage(String code, String msg, Object result, Object accessToken,String sessionId) {
        this.code = code;
        this.msg = msg;
        this.result = result;
        this.accessToken = accessToken;
        this.sessionId = sessionId;
    }
    public static HttpMessage createSuccessMsg(Object o) {
        return new HttpMessage(ResultCode.SUCCESS.getCode(), ResultCode.SUCCESS.getMsg(), o, null,"");
    }

    public static HttpMessage createSuccessMsg(Object o,String msg) {
        return new HttpMessage(ResultCode.SUCCESS.getCode(), msg, o, null,"");
    }

    public static HttpMessage createSuccessMsg(Object o,Object accessToken)
    {
        return new HttpMessage(ResultCode.SUCCESS.getCode(), ResultCode.SUCCESS.getMsg(), o,accessToken,"");
    }

    public static HttpMessage createSuccessMsg(Object o,Object accessToken,String sessionId)
    {
        return new HttpMessage(ResultCode.SUCCESS.getCode(), ResultCode.SUCCESS.getMsg(), o,accessToken,sessionId);
    }

    public  static HttpMessage createErrorMsg(String errorMsg)
    {
        return createErrorMsg(errorMsg,ResultCode.COMMONERROR.getCode());
    }

    public  static HttpMessage createErrorMsg(String errorMsg, String code)
    {
        return new HttpMessage(code,errorMsg,null,"","");
    }

    public static HttpMessage createErrorMsg(Exception e){

        return new HttpMessage(e.getMessage(),ResultCode.COMMONERROR.getCode(),e,null,"");
    }
}
